package com.warmlight.voicepacket.service;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;

import com.warmlight.voicepacket.bean.comm.PictureBean;
import com.warmlight.voicepacket.common.Constants;

/**
 * 媒体下载工具类
 */
public class DownloadUtil {

    public static void downloadCallMedia(Context context, PictureBean videoEntity){
        if(context == null || videoEntity == null){
            return;
        }

        MultimediaInfo multimediaInfo = new MultimediaInfo();

        String videoUrl = videoEntity.getFileName();
        String videoName = "";
        if(!TextUtils.isEmpty(videoUrl)){
            String videoUrlArray[] = videoUrl.split("/");
            videoName = videoUrlArray[videoUrlArray.length - 1];
        }

        String videoPath = Constants.CALL_PICTURE_FILE_PATH + "/" + videoName;

        multimediaInfo.setVideoName(videoName);

        multimediaInfo.setVideoPath(videoPath);

        multimediaInfo.setMultimediaId(String.valueOf(videoEntity.getId()));

        multimediaInfo.setVideoUrl(videoEntity.getFileName());

        Intent videoIntent = new Intent(context,DownLoadVideoService.class);
        videoIntent.setAction("NewVideoTask");
        videoIntent.putExtra("MediaInfo", multimediaInfo);
        context.startService(videoIntent);
    }

}
